//
//  THTaskHomeVC.m
//  YJB
//
//  Created by YJB on 2016/12/16.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THTaskHomeVC.h"
#import "THCustomTabBar.h"
#import "masonry.h"
#import "THTaskHallVC.h"
#import "THMyPublishTaskVC.h"
#import "THMyJoinTaskVC.h"

@interface THTaskHomeVC ()
@property(nonatomic,weak)UIView *currentShowView;
@end

@implementation THTaskHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kUIColorFromRGB(0xfff5f0);
    //self.view.backgroundColor = [UIColor redColor];
    self.title = @"任务赚钱";
    THCustomTabBar *customTabBar = [[THCustomTabBar alloc]init];
    customTabBar.isTask = YES;
    [self.view addSubview:customTabBar];
    YJWeakSelf
    customTabBar.tabBarItemClickBlock = ^(THCustomTabBarItemType type){
        [weakSelf tabBarItemClick:type];
    };
    [customTabBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(49);
    }];
    
    //任务大厅
    THTaskHallVC *taskHallVC = [[THTaskHallVC alloc]init];
    [self addChildViewController:taskHallVC];
    taskHallVC.view.x = 0;
    taskHallVC.view.y = 0;
    taskHallVC.view.width = self.view.width;
    taskHallVC.view.height = IPHONE_H - 49;
    [self.view addSubview:taskHallVC.view];
    self.currentShowView = taskHallVC.view;
    //我发布的
    THMyPublishTaskVC *myPublishVC = [[THMyPublishTaskVC alloc]init];
    [self addChildViewController:myPublishVC];
    //我参与的
    THMyJoinTaskVC *myJoinVC = [[THMyJoinTaskVC alloc]init];
    [self addChildViewController:myJoinVC];
    
}

- (void)tabBarItemClick:(THCustomTabBarItemType)type
{
    [self.currentShowView removeFromSuperview];
    UIViewController *currentVC = nil;
    switch (type)
    {
        case THCustomTabBarItemTypeHall:
            currentVC = self.childViewControllers[0];
            break;
        case THCustomTabBarItemTypeMyPublish:
            currentVC = self.childViewControllers[1];
            break;
        case THCustomTabBarItemTypeMyJoin:
            currentVC = self.childViewControllers[2];
            break;
    }
    currentVC.view.x = 0;
    currentVC.view.y = 0;
    currentVC.view.width = self.view.width;
    currentVC.view.height = IPHONE_H - 49 - 64;
    [self.view addSubview:currentVC.view];
    self.currentShowView = currentVC.view;
    
}

@end
